package edu.sctu.zcy.month201505.day20150526.homeworkchen;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * Created by user24 on 2015/5/26.
 */
public class Student {

    public String name;
    public String sex;
    public int age;
    public String department;//系别
    public Card card ;

    public Student(){}
    public Student(String name, String sex, int age, String department) {

        System.out.println("学生基本信息：");
        System.out.println("姓名：" + name);
        System.out.println("性别：" + sex);
        System.out.println("年龄：" + age);
        System.out.println("系别：" + department);

    }

    public int getQueueNumber(){

        int[] queueNumber = new int[7];
        for (int i = 0; i < queueNumber.length ; i++) {

            queueNumber[i] = i;
        }
        int theNumber = queueNumber[(int)(Math.random()*queueNumber.length)];
        return theNumber;
    }

    public void selectWindowAndFood(){

        Window window = new Window();
        HashMap<Integer,Food> windowQueue = window.getWindowNumberaAndFood();

        int windowNumber = (int) (Math.random()*5);

        System.out.println("学生选择的窗口编号："+windowNumber);
        System.out.println("选择食物："+windowQueue.get(0).getFoodO()[2]+"和"
                +windowQueue.get(0).getFoodT()[2]);

    }

    public void startSwipingCard(){


        Food foodOne = new Food();
        int price = (int) foodOne.getFoodOne().get(foodOne.getFoodO()[2]);
        int price1 = (int) foodOne.getFoodTwo().get(foodOne.getFoodT()[2]);
        card = new Card();
        int money = card.getBalance();

        if (price + price1 > money) {

            System.out.println("余额不足，请充值,消费失败");
            System.out.println("余额为" + money + "元");
            System.exit(0);

            if (money != 0 && Math.min(price, price1) < money && money < Math.max(price, price1)) {
                System.out.println("\n你可以选择其他菜品进行消费,请重新选择菜品,建议你选择素菜。");
            }

        } else {
            System.out.println("本次消费" + (price + price1) + "元");
            System.out.println("消费成功");
            System.out.println("卡上余额：" + (money - (price + price1)));

        }
    }


    public int getSeat() {

        DiningRoom diningRoom = new DiningRoom();
        int[] setSeat = diningRoom.setSeat();
        int get = 0;

        lable:
        for (int i = 1; i < setSeat.length; i++) {

            int number = setSeat[(int) (Math.random() * setSeat.length)];
            if (setSeat[number] == 2 * i) {

                System.out.println(number + "号座位上已有人,请重新选择！");
                continue lable;

            } else {
                get = number;
                System.out.println(get + "号座位可以坐");
                break lable;

            }
        }

        return get;
    }

    public void haveTheFood(){

        System.out.println();
        System.out.println("学生选择排队的人数为："+getQueueNumber());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        Date date = new Date();
        System.out.println("开始排队的时间" + simpleDateFormat.format(date));
        System.out.println("大概5分钟后，开始点菜");

        selectWindowAndFood();
        startSwipingCard();

        System.out.println("学生选择的座位号：" + getSeat());
    }
}

